# coding=utf-8
import unittest
import requests
import os, sys
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parentdir)

class TestGuestSign(unittest.TestCase):
	'''嘉宾签到'''
	def setUp(self):
		self.base_url = "http://127.0.0.1:8000/api/user_sign/"

	def tearDown(self):
		print(self.result)

	def test_eid_phone_null(self):
		'''eid和phone都为空'''
		payload = {'eid':'','phone':''}
		r = requests.post(self.base_url, data=payload)
		self.result = r.json()
		self.assertEqual(self.result['status'],10021)
		self.assertEqual(self.result['message'],'parameter error')

	def test_eid_noexist(self):
		'''发布会id不存在'''
		payload = {'eid':100,'phone':13511001110}
		r = requests.post(self.base_url, data=payload)
		self.result = r.json()
		self.assertEqual(self.result['status'],10022)
		self.assertEqual(self.result['message'],'event id null')

	def test_eid_status(self):
		'''发布会关闭'''
		payload = {'eid':3,'phone':13511001110}
		r = requests.post(self.base_url,data=payload)
		self.result = r.json()
		self.assertEqual(self.result['status'],10023)
		self.assertEqual(self.result['message'],'event status is not available')

	def test_event_status(self):
		'''发布会已开始'''
		payload = {'eid':5,'phone':13511001110}
		r = requests.post(self.base_url,data=payload)
		self.result = r.json()
		self.assertEqual(self.result['status'],10024)
		self.assertEqual(self.result['message'],'event has started')

	def test_guest_phone_no_exist(self):
		'''手机号不存在'''
		payload = {'eid':1,'phone':13511001110}
		r = requests.post(self.base_url,data=payload)
		self.result = r.json()
		self.assertEqual(self.result['status'],10025)
		self.assertEqual(self.result['message'],'user phone null')

	def test_guest_null(self):
		'''不存在已id与phone联合主键存在的数据'''
		payload = {'eid':1,'phone':13511001102}
		r = requests.post(self.base_url,data=payload)
		self.result = r.json()
		self.assertEqual(self.result['status'],10026)
		self.assertEqual(self.result['message'],'user did not participate in the conference')

	def test_guest_havesign_(self):
		'''嘉宾已经签到过'''
		payload = {'eid':1,'phone':13535782980}
		r = requests.post(self.base_url,data=payload)
		self.result = r.json()
		self.assertEqual(self.result['status'],10027)
		self.assertEqual(self.result['message'],'user has sign in')

	def test_guest_sign_success(self):
		'''签到成功'''
		payload = {'eid':1,'phone':13511001100}
		r = requests.post(self.base_url,data=payload)
		self.result = r.json()
		self.assertEqual(self.result['status'],200)
		self.assertEqual(self.result['message'],'sign success')
		

